﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Sql;
using System.Data.Common;
using System.Data.SqlClient;


namespace sccf
{
    public class GenerarAgendaModel
    {
        static SqlConnection connection = new SqlConnection(Vars.connectionString);

        public static void Registrar(int id, int estado)
        {

            connection.Open();
            SqlCommand cmd = new SqlCommand("ActEstado", connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter Id = new SqlParameter("@Id", id);
            SqlParameter Estado = new SqlParameter("@Estado", estado);
            SqlParameter UsuAgenda= new SqlParameter("@UsuAgenda", Vars.Usuario);
            cmd.Parameters.Add(Id);
            cmd.Parameters.Add(Estado);
            cmd.Parameters.Add(UsuAgenda);
            cmd.ExecuteNonQuery();
            connection.Close();
        }

        public static SqlDataReader ObtenerDocs(int idpunto)
        {
            SqlConnection connection = new SqlConnection(Vars.connectionString);
            connection.Open();
            SqlCommand cmd = new SqlCommand("ObtenerDocs", connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter p = new SqlParameter("@id", idpunto);
            cmd.Parameters.Add(p);
            return cmd.ExecuteReader();
        }

        public static SqlDataReader ObtenerPuntos()
        {

            SqlConnection connection = new SqlConnection(Vars.connectionString);
            connection.Open();
            SqlCommand cmd = new SqlCommand("ObtenerPuntosParaGenerarAgenda", connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            return cmd.ExecuteReader();
        }



        public static SqlDataReader ObtenerPuntosPos()
        {

            SqlConnection connection = new SqlConnection(Vars.connectionString);
            connection.Open();
            SqlCommand cmd = new SqlCommand("ObtenerPuntosPospuestos", connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            return cmd.ExecuteReader();
        }



        internal static string verificarfecha()
        {
            connection.Open();
            SqlCommand cmd = new SqlCommand("fechalim", connection);
            SqlDataReader fechalim = cmd.ExecuteReader();


            if (fechalim.Read())
            {
                string fecha =fechalim["FechaLimPuntos"].ToString();
                connection.Close();
                return fecha;
            }
            else
            {
                connection.Close();
                return null;
            }
        }

    }
}